package cn.bob.org.service.impl;


import cn.bob.basic.query.MovleQuery;
import cn.bob.basic.utils.PageList;
import cn.bob.org.domain.Movle;
import cn.bob.org.mapper.MovleMapper;
import cn.bob.org.service.MovleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class MovleServiceImpl implements MovleService {
    @Autowired
    private MovleMapper movleMapper;

    @Override
    public void addMovle(Movle movle) {
        movleMapper.addMovle(movle);
    }

    @Override
    @Transactional
    public void delMovle(Long id) {
        movleMapper.delMovle(id);
    }

    @Override
    @Transactional
    public void updateMovle(Movle movle) {
        movle.setCreatetime(new Date());
        movleMapper.updateMovle(movle);
    }

    @Override
    public List<Movle> findMovleAll() {
        return movleMapper.findMovleAll();
    }

    @Override
    public Movle findByMovleId(Long id) {
        return movleMapper.findByMovleId(id);
    }

    @Override
    public Integer queryCount(MovleQuery query) {
        return movleMapper.queryCount(query);
    }

    @Override
    public PageList<Movle> queryByPage(MovleQuery movleQuery) {
        // 查询条数
        Integer totals = movleMapper.queryCount(movleQuery);
        if (null ==totals || totals==0){
            return new PageList<>(new ArrayList<>(),0);
        }
        // 查询数据
        List<Movle> movlePageList = movleMapper.queryByPage(movleQuery);
        return  new PageList<>(movlePageList,totals);
    }
}
